package com.mnf.server.component;

import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.nio.SelectChannelConnector;

public abstract class AbstractHttpServer implements HttpServer {
	
	private Server jettyServer;
	
	public AbstractHttpServer(String ipAddress, int port) {
		jettyServer = new Server();
		
		SelectChannelConnector connector = new SelectChannelConnector();
		connector.setHost(ipAddress);
		connector.setPort(80);
		connector.setName("admin");

		jettyServer.setConnectors(new Connector[] {connector});
		
		jettyServer.setHandler(createHandler());
	}	


	protected abstract Handler createHandler();


	@Override
	public void start() throws Exception {
		jettyServer.start();
	}

	@Override
	public void stop() throws Exception {
		jettyServer.stop();
	}

}
